<?php
namespace app\index\controller;

use app\common\controller\Base;
use app\common\controller\IndexBase;
use app\common\service\TransmitSms;
use think\Db;
use think\Session;


class Proceeds extends  IndexBase
{

    //收益记录
    public function index(){

        $data = input("param.");
        if( isset($data["type"]) && !empty($data["type"]) ){
            $type = $data["type"];
        }else{
            $type = 1;
        }

        $this->titleName = "收益明细";
        $this->assign("type",$type);
        return $this->fetch();
    }

    public function ajax_list(){

        if( request()->isAjax() ){

            $map = input("post.");
            //print_r($map);exit;
            $model = "account_log";
            $filed = "money,reason_id,add_time,other";
            $where = " user_id = ".$this->userInfo["id"];
            if( $map["type"] == 1 ){
                $where .= " AND reason_id = 1 ";
            }elseif( $map["type"] == 2 ){

                $where .= " AND reason_id = 2 ";
            }elseif( $map["type"] == 3 ){
                $where .= " AND reason_id = 3 ";
            }elseif( $map["type"] == 4 ){
                $where .= " AND reason_id = 4 ";
            }elseif( $map["type"] == 5 ){
                $where .= " AND reason_id = 5 ";
            }

            $pageCount = 10;
            $pageNum = $map["pageNum"];
            if(empty($pageNum)){
                $pageNum = 1;
            }
            $pageRow = ($pageNum - 1)*$pageCount;

            $list = Db::name($model)
                ->field($filed)
                ->where($where)
                ->limit($pageRow,$pageCount)
                ->select();
            if( empty($list) ){
                $retArr = [
                    "result" => 6,
                    "msg" => "没有更多收益了",
                ];
                $this->json_return($retArr);
            }
            /*if( $model == "StaticProceeds" ){

                foreach($list as $k=>$v){
                    $list[$k]["time"] = date("Y-m-d H:m:s",$v["c_time"]);
                    $list[$k]["typeName"] = "静态收益";
                    $list[$k]["source_id"] = "0";
                }
            }else{*/
                foreach($list as $k=>$v){
                    $list[$k]["time"] = date("Y-m-d H:m:s",$v["add_time"]);
                    $list[$k]["typeName"] = $this->get_typeName($v["reason_id"]);
                    /*if(strpos($v["order_code"],'gw') !== false){

                        $M_Order = Db::name("PackageOrder");
                    }else{

                        $M_Order = Db::name("ActivationOrders");
                    }*/
                    $list[$k]["source_id"] = $v['other'];
                }
            /*}*/

            $retArr = [
                "result" => 0,
                "msg" => $list,
            ];
            $this->json_return($retArr);
        }
    }

    private function get_typeName($type){
        $typeName = "提成";
        if( $type == 1 ){
            $typeName = "提成";
        }elseif( $type == 2 ){
            $typeName = "绩效奖";
        }elseif( $type == 3 ){
            $typeName = "管理奖";
        }elseif( $type == 4 ){
            $typeName = "平级奖";
        }else{
            $typeName = "推荐奖";
        }
        return $typeName;
    }

}
